package com.force.module.mcpclient.service.impl;


import cn.hutool.json.JSONUtil;
import com.force.module.mcpclient.domain.AppUser;
import com.force.module.mcpclient.repo.AppUserRepo;
import com.force.module.mcpclient.service.IUserInfoService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserInfoServiceImpl implements IUserInfoService {

    @Autowired
    AppUserRepo appUserRepo;


    private static final Logger log = LoggerFactory.getLogger(UserInfoServiceImpl.class);

    @Override
    public String getUserByName(String name) {
        log.info("正在执行查询");
        AppUser appUserByName = appUserRepo.getAppUserByName(name);
        if (null!=appUserByName) {
            log.info("用户信息{}", JSONUtil.toJsonStr(appUserByName));
            return appUserByName.getUserDesc();}
        return "非法用户";
    }

    @Override
    public String saveOneInfo(String name, String desc) {
        log.info("正在执行保存");
        AppUser appUserByName = appUserRepo.getAppUserByName(name);
        if (null!=appUserByName) {
            appUserByName.setUserDesc(desc);
        }else{
            appUserByName=new AppUser();
            appUserByName.setUserDesc(desc);
            appUserByName.setUserName(name);
        }
        appUserRepo.saveOrUpdate(appUserByName);
        log.info("执行结束");
        return "保存成功";
    }
}
